//
//  HNSH_EcologyViewController.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/8/26.
//

#import "HNSH_EcologyViewController.h"

#import "HNSH_EcologyViewCell.h"

@interface HNSH_EcologyViewController ()

/* dataArray */
@property (nonatomic, strong) NSArray *dataArray;

@end

static NSString *HNSH_EcologyViewCellID = @"HNSH_EcologyViewCellID";

@implementation HNSH_EcologyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self configCollectionView];
}

- (void)configCollectionView {
    [self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    [self.collectionView registerClass:[HNSH_EcologyViewCell class] forCellWithReuseIdentifier:HNSH_EcologyViewCellID];
}

- (void)loadNewData{
//    [HNSH_UserNetServer requestPartnerPoundageConfigSuccess:^(ST_BaseNetModel * _Nullable responseObject) {
//        [self.collectionView.mj_header endRefreshing];
//        if (responseObject.code == 0) {
//            NSArray * configs = responseObject.resultset[@"configs"];
//            self.dataArray = [NSArray yy_modelArrayWithClass:HNSH_LevelModel.class json:configs];
//            [self.collectionView reloadData];
//        } else {
//            [self.view makeToast:responseObject.msg];
//        }
//    } Failure:^(NSError * _Nullable error) {
//
//    }];
}

- (NSArray *)dataArray {
    if (!_dataArray) {
        _dataArray = @[];
        if (self.parameter == 0) {
            _dataArray = @[@"优酷会员",@"爱奇艺",@"腾讯会员",@"芒果TV",@"搜狐视频",
                           @"QQ音乐",@"QQ会员",@"QQ黄钻",@"PPTV",@"1905电影网",
                           @"腾讯体育",@"人人视频",@"蜻蜓FM",@"南瓜电影",@"陌陌",
                           @"酷我音乐",@"酷狗音乐",@"百度网盘",@"哔哩哔哩"];
        } else if (self.parameter == 1) {
            _dataArray = @[@"星巴克",@"肯德基",@"麦当劳",@"百果园",@"必胜客",
                           @"哈根达斯",@"喜茶",@"奈雪的茶",@"瑞幸咖啡",@"幸福西饼",
                           @"DQ冰淇淋"];
        } else if (self.parameter == 2) {
            _dataArray = @[@"知乎",@"樊登读书",@"作业帮",@"WPS",@"QQ阅读",
                           @"百度文库",@"多看阅读",@"凯叔讲故事",@"快看漫画",@"懒人听书",
                           @"掌阅"];
        } else if (self.parameter == 3) {
            _dataArray = @[@"饿了么",@"美团",@"美团外卖"];
        } else if (self.parameter == 4) {
            _dataArray = @[@"盒马鲜生",@"山姆超市",@"世纪联华",@"京东E卡",@"每日优鲜",
                           @"屈臣氏",@"全家",@"苏宁",@"天猫超市",@"网易考拉",
                           @"网易严选",@"沃尔玛"];
        }
    }
    return _dataArray;
}

//MARK: UICollectionViewDelegate Methods
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    HNSH_EcologyViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:HNSH_EcologyViewCellID forIndexPath:indexPath];
    cell.imgV.image = [UIImage imageNamed:[NSString stringWithFormat:@"ecology_%ld_%ld",self.parameter,indexPath.row]];
    cell.titleLabel.text = self.dataArray[indexPath.row];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake((kScreenWidth - 20)/5, 61);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(16, 10, 0, 10);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 16;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    [self.view makeToast:@"暂未开放"];
}

@end
